#include "tim_app.h"

void Tim_set_duty(uint16_t duty)
{
    TIM3->CCR2 = (TIM3->ARR +1 )* (duty / 100.0f);
}

void Tim_set_freq(uint16_t freq)
{
    uint32_t Clock_freq = 1000000;

    uint32_t value = Clock_freq / freq - 1;

    TIM3->CCR2 = (value + 1) * (TIM3->CCR2 / TIM3->ARR);

    TIM3->ARR = value;

    TIM3->EGR = TIM_EGR_UG;
}

void tim_proc(void)
{

}

uint32_t ic_data[30];
uint32_t ic_value;
float Freq;
void IC_proc(void)
{
    for (int i = 0; i < 30;i++)
    {
        ic_value += ic_data[i];
    }

    ic_value /= 30.0f;
    Freq = 1000000.0f / ic_value;
}